Repository navigation
fix(id): reject duplicate same-file saves while one is in flight (#2466) - #4193
Conversation
SaveRateLimiter::check only sees completed saves, so two overlapping saves of one file both passed the cooldown and the slower one could win the filename tag. The limiter now hands out a SavePermit via acquire(): the cooldown check plus an in-flight reservation taken atomically under a std Mutex<HashSet> (released synchronously by Drop on every handler exit path, so a failed save strands neither the reservation nor a cooldown). save_handler acquires at entry — a same-file arrival while a save is in flight gets the existing 429 Save rate limited. Try again in Ns. contract — and completes the permit where record() used to run. Four regression tests drive the limiter in the handler pattern: in-flight refusal, concurrent acquires admit exactly one, dropped permit releases without recording, completed permit records the cooldown.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 32 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
|
🤖 Agent note · task 5358 (lane C) follow-up: the laptop |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 16e517893a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- Add the pkgs/id design record for the acquire/SavePermit save reservation (docs protocol): lifecycle, failure cleanup, and the synchronous-mutex choice. - AutoSaveManager.onNewVersion no longer cancels a pending rate-limit retry: the broadcast version comes from the save that won the in-flight race and cannot contain the rejected snapshot, so clearing the retry marked never-persisted content as saved. New vitest cases pin both the preserved retry and the unchanged no-retry behavior.
…race # Conflicts: # pkgs/id/src/web/routes.rs
Fixes #2466:
SaveRateLimiter's check/record split let two overlapping saves of the same file both pass the 5s cooldown, and the slower save could win the filename tag, silently reverting the newer save.Change
SaveRateLimiter::acquire(pkgs/id/src/web/mod.rs): the cooldowncheckplus an in-flight reservation taken atomically under astd::sync::Mutex<HashSet<String>>(O(1) touches only, never held across an await; a std mutex precisely soDropcan release synchronously). If the name is already in flight, the caller getsErr(cooldown)and the handler answers with the existing429+Save rate limited. Try again in Ns.contract — the behaviour the issue's acceptance pins.SavePermit: dropping it releases the reservation;complete()records the save first. Every early error path in the handler therefore clears the reservation without recording a cooldown, so a failed save never strands the filename.save_handler(routes.rs): acquires where it previously only checked, and completes the permit whererecord()used to run at the end. Successful-save cooldown behaviour is unchanged; the filename tag is now always set by the single accepted save, so it names the last-accepted revision.Tests
Four new limiter tests in the handler's call pattern (existing limiter tests untouched):
Verification:
cargo check --testson the laptop + CI on merge per fleet policy. Refs: task 5358; sibling defect #1713 (map eviction) is already handled on main and is untouched here.Need help on this PR? Tag
@codesmith-botwith what you need.